{% extends "base.html" %}
{% load i18n dv_filters bootstrap3 %}

{% block head_title %}{% blocktrans with year=export_period.year season=export_period.season|season_verb %}Calendrier de la saison {{ season }} {{year}}{% endblocktrans %}{% endblock %}

{% block container-class %}container-fluid{% endblock %}

{% block content %}
    {% include 'info/_season_nav.html' with nav_url=nav_url previous_period=previous_period next_period=next_period only %}
    <h1>
      {% blocktrans trimmed with year=export_period.year season=export_period.season|season_verb %}
        Calendrier de la saison {{ season }} {{year}}
      {% endblocktrans %}
    </h1>

    {% if form %}
        <div class="modal fade bs-user-filters-modal" tabindex="-1" role="dialog" aria-labelledby="filters">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="{% trans "Fermer" %}"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">{% trans "Filtrer le calendrier" %}</h4>
                    </div>
                    <div class="modal-body">
                    <form method="POST" action="" class="form-inline"  style="display: inline;" novalidate>
                        {% csrf_token %}
                        {% bootstrap_form form size='small' show_help=False %}

                        <div class="modal-footer">
                            {% buttons %}
                                <a href="{% url 'qualifs-calendar' %}" class="btn btn-default">{% trans 'Reset' %}</a>
                                <button type="submit" class="btn btn-primary">{% trans 'Filtrer' %}</button>
                            {% endbuttons %}
                        </div>
                    </form>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}

    <div class="hidden-print">
        {% include 'export_buttons.html' with exporturl=dataset_exporturl year=export_period.year season=export_period.season %}

        {% if form %}
            <button type="button" class="btn btn-primary pull-right" data-toggle="modal" data-target=".bs-user-filters-modal">
                <span class="glyphicon glyphicon-filter" aria-hidden="true"></span>
                {% trans "Filtrer" %}
            </button>
        {% endif %}
    </div>

{% if date_sessions %}
    <table class="table table-striped table-bordered dvqualifs-calendar">
        <thead>
            <tr><td></td>
            {% for struct in date_sessions|slice:":7" %}
                <th class="text-center">{{ struct.day|date:'l' }}</th>
            {% endfor %}
            </tr>
        </thead>
        {% for struct in date_sessions %}
            {% if struct.day.weekday == 0 %}
                <tr><th>{{ struct.day|weeknumber }}</th>
            {% endif %}
            <td>
                <p class="text-center">{{ struct.day|date_ch_short }}</p>
                {% for session in struct.sessions %}
                    <a class="dvstate-bg-{{ session.orga.address_canton|lower }}"{% if session.season and user|anyofusercantons:session.season.cantons %} href="{% url 'session-detail' seasonpk=session.season.pk pk=session.id %}"{% endif %}>
                        {% if session.begin %}<span class="badge pull-right dvstate-bg-none dvstate-txt-{{ session.orga.address_canton|lower }} ">{{ session.begin }}</span>{% endif %}
                        {{ session.orga.ifabbr|safe }}<span class="small visible-print-inline"> ({{ session.orga.address_canton|canton_abbr:True }})</span>
                    </a>
                {% endfor %}
            </td>
            {% if struct.day.weekday == 6 %}
                </tr>
            {% endif %}
        {% endfor %}
    </table>

    <table class="table table-bordered dvqualifs-calendar">
        <tfoot><tr>
        {% for canton in legend_cantons %}
        <th class="text-center dvstate-bg-{{ canton|lower }}">{{canton|canton_abbr:False}}</th>
        {% endfor %}
        </tr></tfoot>
    </table>
{% else %}
    <div class="alert alert-warning row" role="alert">
        {% trans "Aucune Qualif’ n’est planifiée pour l’instant!" %}
    </div>
{% endif %}

{% endblock %}

